package ac.il.technion.c236369.hw4.core.entity;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.http.entity.AbstractHttpEntity;


public class EntityTemplate extends AbstractHttpEntity{

	
	private SizedContentProducer producer;

	public EntityTemplate( SizedContentProducer producer) {
        super();
        if (producer == null) {
            throw new IllegalArgumentException("Content producer may not be null");
        }
        this.producer = producer; 
    }

    public long getContentLength() {
        return producer.getContentLength( ) ;
    }

    public InputStream getContent() {
        throw new UnsupportedOperationException("Entity template does not implement getContent()");
    }

    public boolean isRepeatable() {
        return true;
    }

    public void writeTo(final OutputStream outstream) throws IOException {
        if (outstream == null) {
            throw new IllegalArgumentException("Output stream may not be null");
        }
        this.producer.writeTo(outstream);
    }

    public boolean isStreaming() {
        return true;
    }

    public void consumeContent() throws IOException {
    }
    
}

